package com.fs.m.server.function.test;

import com.fs.m.server.domain.RequestContext;
import com.fs.m.server.domain.Result;
import com.fs.m.server.function.Function;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 分类列表
 *
 * User: zhuguoyin
 * Date: 13-10-7
 * Time: 下午7:51
 * To change this template use File | Settings | File Templates.
 */
public class CategoryListFunction1 implements Function {
    @Override
    public Result execute() throws Exception {
        Result result = new Result();
        List categoryList = new ArrayList();
        Map category = new HashMap();
        category.put("name", "女生系列");
        category.put("id", 12213);
        category.put("url", "http://www.baidu.com");
        if (showItems()) {
            addItems(category);
        }
        categoryList.add(category);

        category = new HashMap();
        category.put("name", "男生系列");
        category.put("id", 12213);
        category.put("url", "http://www.baidu.com");
        if (showItems()) {
            addItems(category);
        }
        categoryList.add(category);

        category = new HashMap();
        category.put("name", "萌宠系列");
        category.put("id", 12213);
        category.put("url", "http://www.baidu.com");
        if (showItems()) {
            addItems(category);
        }
        categoryList.add(category);
        result.addResultData("categoryList", categoryList);
        return result;
    }

    private void addItems(Map category) {
        List items = new ArrayList();
        Map item = new HashMap();
        item.put("id", 112);
        item.put("name", "摩丝摩丝");
        item.put("url", "http://www.baidu.com");
        items.add(item);
        item = new HashMap();
        item.put("id", 112);
        item.put("name", "摩丝摩丝");
        item.put("url", "http://www.baidu.com");
        items.add(item);
        item = new HashMap();
        item.put("id", 112);
        item.put("name", "摩丝摩丝");
        item.put("url", "http://www.baidu.com");
        items.add(item);
        category.put("items", items);
    }

    private boolean showItems() {
        Object showItems = RequestContext.get().getParam().get("showItems");
        return "true".equals(showItems);
    }
}
